package service

import (
	"changeme/service/mywindow"
	"github.com/wailsapp/wails/v3/pkg/application"
	"log"
	"time"
)

func InitTray(app *application.App) {
	toolsWindow := mywindow.NewToolsWindow(app)

	// 系统托盘
	systemTray := app.NewSystemTray()
	myMenu := app.NewMenu()

	myMenu.Add("主界面").OnClick(func(ctx *application.Context) {
		mainWindow := app.GetWindowByName("main")
		mainWindow.Show()
	})
	myMenu.Add("工具箱").OnClick(func(ctx *application.Context) {
		toolsWindow.Show()
	})
	myMenu.AddSeparator()
	myMenu.Add("测试01").OnClick(func(ctx *application.Context) {
		app.EmitEvent("timemsg", "006")
	})
	myMenu.Add("测试03").OnClick(func(ctx *application.Context) {
		log.Printf("测试04")
		now := time.Now().Format(time.RFC1123)
		app.EmitEvent("timemsg", now)
	})
	myMenu.AddSeparator()
	myMenu.Add("退出").OnClick(func(ctx *application.Context) {
		app.Quit()
	})

	systemTray.SetMenu(myMenu)

	systemTray.OnClick(func() {
		mainWindow := app.GetWindowByName("main")
		//show是出现在任务栏，不一定展示在屏幕最前面
		mainWindow.Show()
		//展示在屏幕最前面
		mainWindow.Focus()
	})
}
